package com.example.computer_exam_training_sys.mapper;

import com.example.computer_exam_training_sys.entity.User_Exams_entity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import java.util.List;

@Mapper
public interface User_Exams_Mapper {
    @Select("select * from user_exams")
    List<User_Exams_entity> findallexams();

    // 按userId条件查询
    @Select("select * from user_exams where user_id = #{userId}")
    List<User_Exams_entity> findByUserId(@Param("userId") Integer userId);
    
    // 插入考试记录
    @Insert("INSERT INTO user_exams(user_id, paper_id, total_score, user_score, create_time, duration) " +
            "VALUES(#{userId}, #{paperId}, #{totalScore}, #{userScore}, #{createTime}, #{duration})")
    @Options(useGeneratedKeys = true, keyProperty = "examId")
    int insertExam(User_Exams_entity exam);
}
